package com.ajun.service.impl;

import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;

import com.ajun.entity.ContentCategory;
import com.ajun.mapper.ContentCategoryMapper;
import com.ajun.service.IContentCategoryService;
import com.ajun.util.PageResult;
import org.springframework.stereotype.Service;


@Service
public class ContentCategoryServiceImpl extends ServiceImpl<ContentCategoryMapper, ContentCategory> implements IContentCategoryService {
    @Override
    public PageResult<ContentCategory> findByPage(Integer page, Integer pageSize) {
        Page<ContentCategory> page1 = this.page(new Page<>(page, pageSize));
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }

    //分页查询
    @Override
    public PageResult<ContentCategory> search(Integer page, Integer pageSize, String name) {
        QueryWrapper<ContentCategory> wrapper = new QueryWrapper<>();
        wrapper.like(StrUtil.isNotBlank(name), "name", name);
        Page<ContentCategory> page1 = this.page(new Page<>(page, pageSize), wrapper);
        return new PageResult<>(page1.getRecords(),page1.getTotal());
    }
}
